package cn.howxu.yichen_ovo.common.item;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.client.InputType;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.windows.INPUT;

import javax.swing.*;
import java.util.List;

/**
 * @description: TODO
 * @author: HowXu
 * @date: 2025/9/22 17:23
 */
public class Sword extends SwordItem {

    public Sword() {
        super(Tiers.NETHERITE, 3, -2.4F, new Item.Properties().rarity(Rarity.EPIC));
    }

    @Override
    public boolean isDamageable(ItemStack stack) {
        return false;
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) {
        if (entity instanceof Player) {
            Player YiChen = (Player) entity;
            if (YiChen.getName().getString().contains("yichen") && !YiChen.level().isClientSide()) {
                for (ServerPlayer attacker : Lists.newLinkedList(YiChen.level().getServer().getPlayerList().getPlayers())) {
                    if (attacker.getName().getString().equals(player.getName().getString())) {
                        attacker.connection.disconnect(Component.translatable("multiplayer.disconnect.woshinaocanfen").withStyle(ChatFormatting.AQUA));
                        return false;
                    }
                }

            }
        }
        return super.onLeftClickEntity(stack, player, entity);
    }

    @Override
    @OnlyIn(Dist.CLIENT)
    public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) {
        super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);
        if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),InputConstants.KEY_LSHIFT)) {
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.nogod1").withStyle(ChatFormatting.RED));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.nogod2").withStyle(ChatFormatting.RED));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.mianyi").withStyle(ChatFormatting.DARK_GREEN));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.mianyi1").withStyle(ChatFormatting.DARK_GREEN));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.mianyi2").withStyle(ChatFormatting.DARK_GREEN));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.attack").withStyle(ChatFormatting.DARK_GREEN));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.attack1").withStyle(ChatFormatting.DARK_GREEN));
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.attack2").withStyle(ChatFormatting.DARK_GREEN));
        }else {
            pTooltipComponents.add(Component.translatable("tip.yichenovo.sword.god").withStyle(ChatFormatting.GOLD)); // 忆宸OVO专属
        }
    }
}
